Pipelines again

In this exercise, we write points and pipes of a diagram in the same format used earlier for reading.

Step 1

Use

relativeResource :: Resource -> String -> <ReadGraph> Resource (Simantics/DB)

Converts a relative URI to a resource starting from the given resource

and

currentModel :: <ReadGraph> Resource (Simantics/DB)

Gives the current active model.

to define a variable dia that refers to some composite (configuration element corresponding to a diagram). Create some content (points and pipes) to the diagram.

Print the value to the console and check that it corresponds to the resource id given by the graph debugger.

Step 2

Import the ontology http://www.simantics.org/Layer0-1.1 as L0.

Use

(#) :: Resource -> Resource -> <ReadGraph> [Resource] (Simantics/DB)

subject # predicate returns all objects with the given subject and predicate.

and L0.ConsistsOf to find all children of dia. Print their names using

map :: FunctorE a => (b -> <d> c) -> a b -> <d> a c (Prelude)

Applies the function to all elements of the container and returns the similarly shaped container with the results:

For lists,

map f [e1, e2, ..., eN] = [f e1, f e2, ..., f eN]

for example

map (*2) [1..5] = [2, 4, 6, 8, 10]
nameOf :: Browsable a => a -> <ReadGraph> String (Simantics/DB)

Reads the name of the value.

Step 3

Import the ontology http://www.apros.fi/Combustion/Configuration-6.0 as Conf.

Modify the commands in step 2 to find only the points (Conf.ModuleTypes.POINT) of the diagram.

Step 4

Print the names and elevations of all points in dia using the function

relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a (Simantics/DB)

Reads the value of a literal that is an object with the given subject and predicate

and the attribute Conf.Relations.PO11_ELEV.

Step 5

Use the relation http://www.simantics.org/Modeling-1.2/ElementToComponent and

singleObject :: Resource -> Resource -> <ReadGraph> Resource (Simantics/DB)

Assumes that there is exactly one object with the given subject and predicate and returns it.

to find the graphical symbol of the point.

Use the relation http://www.simantics.org/Diagram-2.2/HasTransform and

relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a (Simantics/DB)

Reads the value of a literal that is an object with the given subject and predicate

to read the transformation of the point. The last two elements of the transformation are the coordinates of the point.

Step 6

Give an indices for all points you find for example using

range :: Integer -> Integer -> [Integer] (Prelude)

range begin end produces a list of consecutive integers starting from begin and ending to end (including end). The compiler supports syntactic sugar [begin..end] for this function.

zip :: [a] -> [b] -> [(a, b)] (Prelude)

Combines two lists into one list of pairs. The length of the resulting list is the length of the smallest input list.

zip [1, 2, 3, 4, 5] ['a', 'b', 'c'] = [(1, 'a'), (2, 'b'), (3, 'c')]

Step 7

Print the data about the points in the format described in the previous pipelines exercise.

Step 8

Print the corresponding data about the pipes.